import {
  searchProductsByTitleAPI
} from '../../api/product'

Page({
  data: {
    searchValue: "",
    productList: [],

  },
  onLoad(options) {
    this.setData({
      searchValue: options.searchValue,
    });
  },
  onShow() {
    this.searchProductsByTitle(this.data.searchValue)
  },
  async searchProductsByTitle(title) {
    let that = this
    await searchProductsByTitleAPI(title).then(res => {
      if (res.code == 200) {
        that.setData({
          productList: res.result,
        })
      }
    })
  },
  jumpDetail(event) {
    const id = event.currentTarget.id;
    wx.navigateTo({
      url: `/pages/detail/detail?id=${id}`,
    });
  },
})